import java.util.regex.*;

public class NSNote {
  
  private String definedPitch;
  private String coreMappedPitch;
  private int octave;
  private double frequency;
  
  public NSNote(String definedNote) {
    boolean acceptableInput = NoteToolbox.validPitch(definedNote);
    if (!acceptableInput) {
      throw new IllegalArgumentException("ERROR: \n" + "Invalid Note String - Mapped Pitches cannot be used to initialize an NSNote object");
    } else {
      
    Pattern pitchPattern = Pattern.compile("^[a-gA-G](#|x|bb|b)?");
    //Pattern octavePattern = Pattern.compile("\\d*");
    
    Matcher m = pitchPattern.matcher(definedNote);
    m.find();
    definedPitch = m.group();
    
    coreMappedPitch = NoteToolbox.mapPitch(definedPitch);
    octave = Integer.parseInt(definedNote.replaceAll(definedPitch, ""));
    System.out.println("NOTE: " + definedNote + " -- PITCH: " + definedPitch + " -- MAPPED PITCH: " + coreMappedPitch);
    //System.out.print(" OCTAVE: " + octave);
    frequency = NoteToolbox.calculateFreq(this);
 
    }
  }
    
  //This is a special constructor used to explicitly set the frequency of a pitch.
  //The purpose for this constructor is establish a reference pitch that has an already defined frequency.
  //Ex.  A4, in twelve-tone equal temperament, is held at 440 Hz (440.0 as a double) officially.
  
  //Note: By changing the pitch class or the octave, the frequency will be altered by the calculateFreq() method.
  
    public NSNote(String definedNote, double definedFrequency) {
      boolean acceptableInput = NoteToolbox.validPitch(definedNote);
    if (!acceptableInput) {
      throw new IllegalArgumentException("ERROR: \n" + "Invalid Note String - Mapped Pitches cannot be used to initialize an NSNote object");
    } else {
      
    Pattern pitchPattern = Pattern.compile("^[a-gA-G](#|x|bb|b)?");
    //Pattern octavePattern = Pattern.compile("\\d*");
    
    Matcher m = pitchPattern.matcher(definedNote);
    m.find();
    definedPitch = m.group();
    
    coreMappedPitch = NoteToolbox.mapPitch(definedPitch);
    octave = Integer.parseInt(definedNote.replaceAll(definedPitch, ""));
    frequency = definedFrequency;
    }
  }
  
  public String getPitch() {
    return definedPitch;
  }
  
  public String getMappedPitch() {
    return coreMappedPitch;
  }
  
  public int getOctave() {
    return octave;
  }
  
  public double getFreq() {
    return frequency;
  }
  
  public String getNote() {
    return definedPitch + octave;
  }
  
  public void setPitch(String pitch) {
  }
  
  public void setOctave(int oct) {
  }
  
  public void setNote(String definedNote) {
    
  }
   
  
}
  
